import wx
import os

from utils import tracer

class Pane(wx.Panel):  
  def __init__(self, parent):
    wx.Panel.__init__(self, parent)
    self._properties = {}
    self.loadConfig()

  def getName(self):
    if self._properties.has_key('Name'):
      return self._properties['Name']
    else:
      return ''

  def getCaption(self):
    if self._properties.has_key('Caption'):
      return self._properties['Caption']
    else:
      return ''

  def showCaption(self):
    if self._properties.has_key('ShowCaption'):
      showCaption = self._properties['ShowCaption']
      if showCaption.lower() == 'true':
        return True
      else:
        return False
    else:
      return False;

  def getPosition(self):
    if self._properties.has_key('Pos'):
      pos = self._properties['Pos']
      if pos.lower() == 'center':
        return wx.CENTER
      elif pos.lower() == 'right':
        return wx.RIGHT
      elif pos.lower() == 'top':
        return wx.TOP
      elif pos.lower() == 'bottom':
        return wx.BOTTOM
      else:
        return wx.LEFT
    else:
      return wx.LEFT

  def getConfigFileName(self):
    return 'config.cfg'

  def loadConfig(self):
    config = open(self.getConfigFileName(), 'r')
    
    tracer.writeln('    - Reading Config File')
    tracer.writeln('      ------------------------------')
    line = ''
    while line.strip(' \t%s' % os.linesep) != '[Pane]':
      line = config.readline()
      tracer.writeln('      | %s' % line)

    while True:
      line = config.readline()
      
      line = line.strip(' \t%s' % os.linesep)
      if line == '':
        break
      
      tracer.writeln('      | %s' % line)
      
      name, value = line.split(':')
      self._properties[name] = value
    
    tracer.writeln('      ------------------------------')
